package org.qianye.soft;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.qianye.soft.test.TestClazzServices;
import org.qianye.soft.util.SpringApplicationContext;

/**
 * JTable分页
 *
 * @author 千叶
 */
class Application {

	private static MainFrame mainFrame;

	/**
	 * 获取主界面
	 *
	 * @return
	 */
	public static MainFrame getMainFrame() {
		return mainFrame;
	}

	/**
	 * 应用程序入口
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// // 去掉JFrame,JDialog 当前的提供窗口装饰
		// JFrame.setDefaultLookAndFeelDecorated(true);
		// JDialog.setDefaultLookAndFeelDecorated(true);
		// // 改变输入法边框
		// System.setProperty("java.awt.im.style", "on-the-spot");
		// try {
		// // 加载Substance皮肤
		// UIManager.setLookAndFeel(new
		// SubstanceBusinessBlueSteelLookAndFeel());
		// } catch (UnsupportedLookAndFeelException ignored) {
		// }
		try {
			try {
				// 加载Substance皮肤
				UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
				Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
			}
		} catch (UnsupportedLookAndFeelException ignored) {
		}

		SwingUtilities.invokeLater(() -> {
			final SplashWindow load = new SplashWindow();
			load.setVisible(true);

			new Thread(() -> {
				load.setProText("加载 配置文件");
				SpringApplicationContext.init(SpringApplicationContext.MYSQL);

				load.setProText("加载 测试数据");
				TestClazzServices.addTestData(10000);

				load.setProText("加载 核心界面");

				mainFrame = new MainFrame(load);
				mainFrame.setVisible(true);
				load.dispose();

			}).start();
		});

		Runtime.getRuntime().addShutdownHook(new Thread(SpringApplicationContext::destroy));

		System.out.println("我是主线程！");
	}
}
